import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:datetime_picker_formfield/time_picker_formfield.dart';

class DateTimePicker extends StatefulWidget {
  @override
  DateTimePickerState createState() {
    return new DateTimePickerState();
  }
}

class DateTimePickerState extends State<DateTimePicker> {
  // final datetimeFormat = DateFormat("EEEE, MMMM d, yyyy 'at' h:mma");
  final datetimeFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
  final dateFormat = DateFormat("yyyy-MM-dd");
  final timeFormat = DateFormat("h:mm a");
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new Builder(
        builder: (BuildContext context) => ListView(
              children: <Widget>[
                DateTimePickerFormField(
                  format: datetimeFormat,
                  onChanged: (date) {
                    Scaffold.of(context)
                        .showSnackBar(SnackBar(content: Text('$date')));
                  },
                ),
                TimePickerFormField(
                  format: timeFormat,
                  onChanged: (time) {
                    Scaffold.of(context)
                        .showSnackBar(SnackBar(content: Text('$time')));
                  },
                ),
                DateTimePickerFormField(
                  dateOnly: true,
                  format: dateFormat,
                  onChanged: (date) {
                    Scaffold.of(context)
                        .showSnackBar(SnackBar(content: Text('$date')));
                  },
                ),
                DateTimePickerFormField(
                  format: datetimeFormat,
                  enabled: false,
                ),
                TimePickerFormField(
                  format: toDateFormat(TimeOfDayFormat.HH_colon_mm),
                  enabled: false,
                ),
              ],
            ),
      ),
    );
  }
}
